/**
 * Created by Admin on 2018/1/4.
 */
define(function (require, exports, module) {
    var template = require("template");
    var loadingTpl = require("../common/tpl/loading.html");
    var tpl = require("./tpl/patAgencyTpl.html");
    require("../common/highchart/highcharts");
    require("../common/highchart/linechart");
    require("../common/highchart/columnChartpatAgency");
    require("../seajs-init");

    var patAgencyAnaly = {
        initTable: function (urlItem) {
            $("#Js_statisticalBox").html(template.compile(loadingTpl));
            $.ajax({
                url: window.jkconfig.webapiurlv + "analysis/AgencyAnalysis/" + urlItem,
                success: function (data) {
                    if (data.code == 0 && data.infos != null) {
                        $(".la-square-jelly-box.la-2x").hide();
                        if (data.infos.length > 0) {
                            $("#Js_statisticalBox").show();
                            $(".nodata-title").hide();
                            var html = template.compile(tpl)({data: data})
                            $("#Js_statisticalBox").html(html);
                            /*遍历info,得到四个数组：agencyName=[],fmcount=[],syxxxount=[],wgsjcount=[]*/
                            for (var i = 0, agencyName = [], fmcount = [], syxxcount = [],
                                     wgsjcount = []; i < data.infos.length; i++) {
                                agencyName.push(data.infos[i].agencyName);
                                fmcount.push(data.infos[i].fmcount);
                                syxxcount.push(data.infos[i].syxxcount);
                                wgsjcount.push(data.infos[i].wgsjcount);
                            }
                            var sourceData = [
                                    {name: '发明专利', data: fmcount},
                                    {name: '实用新型', data: syxxcount},
                                    {name: '外观专利', data: wgsjcount}
                                ],
                                title = "代理机构统计",
                                //线形图初始化
                                linechart = new ColumnChart({
                                    dom: "ptamountchart",
                                    xData: agencyName,
                                    yData: sourceData,
                                    title: title,
                                    legend: {
                                        layout: 'top',
                                        align: 'center',
                                        floating: false
                                    }
                                });
                        } else {
                            $("#ptamountchart").html('<div class="nodata-title">暂无数据</div>');
                            $("#Js_statisticalBox").hide();
                            $(".nodata-title").show();
                        }
                    } else {
                        $("#ptamountchart").html('<div class="nodata-title">暂无数据</div>');
                        $("#Js_statisticalBox").hide();
                        $(".nodata-title").show();
                    }
                }
            })
        }
    }

    $(function () {
        patAgencyAnaly.initTable(1);
        $("[name=agencyType]").change(function () {
            patAgencyAnaly.initTable($(this).val());
        })
        $("body").on("click", ".btnExport", function () {
            window.parent.location.href = window.jkconfig.webapiurlv + "analysisexcel/AgencyAnalysis/" + $("[name=agencyType]").val() + "?" + api_key + "=" + token;
        }).on("click", ".btnJumpArea", function () {
            window.top.location.href = "/index.html#/analysis/patSearch.html";
            localStorage.setItem("agencyName", $(this).html());
        }).on("click", ".btnJumpFmcount", function () {
            localStorage.setItem("patHubTypeName", JSON.stringify(['发明公开', '发明授权']));
            localStorage.setItem("agencyName", $(this).attr("data-agency"));
            if ($("[name=agencyType]").val() == 1) {
                localStorage.setItem("lawState", JSON.stringify([1]));
            }
            window.top.location.href = "/index.html#/analysis/patSearch.html";
        }).on("click", ".btnJumpSyxxcount", function () {
            localStorage.setItem("patHubTypeName", JSON.stringify(['实用新型']));
            localStorage.setItem("agencyName", $(this).attr("data-agency"));
            if ($("[name=agencyType]").val() == 1) {
                localStorage.setItem("lawState", JSON.stringify([1]));
            }
            window.top.location.href = "/index.html#/analysis/patSearch.html";
        }).on("click", ".btnJumpWgsjcount", function () {
            localStorage.setItem("patHubTypeName", JSON.stringify(['外观设计']));
            localStorage.setItem("agencyName", $(this).attr("data-agency"));
            if ($("[name=agencyType]").val() == 1) {
                localStorage.setItem("lawState", JSON.stringify([1]));
            }
            window.top.location.href = "/index.html#/analysis/patSearch.html";
        }).on("click", ".btnJumpApplicantCount", function () {
            // localStorage.setItem("applyPerson",$(this).html());
            // localStorage.setItem("agencyName",$(this).attr("data-agency"));
            window.top.location.href = "/index.html#/analysis/patSearch.html";
        })

    })
})